<template>
    <x-page class="page-notes" title="修改笔记">
        <template slot="main">
            <cube-form :schema="schema" :model="model" @validate="onValidate" @submit="onSave">
            </cube-form>
        </template>
    </x-page>
</template>
<script>
import XPage from 'src/mobile/components/XPage';
import API from 'src/api/repository/notes';
import { EditCrud } from 'src/mobile/crud';

export default {
    components: {
        XPage
    },
    data() {
        return {
            ...EditCrud.data(),
            validity: {},
            valid: null,
            model: {
                id: null,
                username: '',
                nickname: '',
                password: '',
                phone: '',
                departmentId: '1',
                type: 'EMPLOYEE'
            },
            options: {
                scrollToInvalidField: true,
                layout: '' // classic fresh
            },
            schema: {
                fields: [
                    {
                        type: 'input',
                        modelKey: 'username',
                        label: '账户',
                        rules: {
                            required: true
                        },
                        trigger: 'blur'
                    },
                    {
                        type: 'input',
                        modelKey: 'password',
                        label: '密码',
                        trigger: 'blur'
                    },
                    {
                        type: 'input',
                        modelKey: 'nickname',
                        label: '昵称',
                        props: {
                        },
                        rules: {
                            required: true
                        },
                        // validating when blur
                        trigger: 'blur'
                    },
                    {
                        type: 'input',
                        modelKey: 'phone',
                        label: '手机',
                        props: {
                            placeholder: '请输入',
                        },
                        rules: {
                            required: true
                        },
                        // validating when blur
                        trigger: 'blur'
                    },
                    {
                        type: 'submit',
                        label: '提 交'
                    }
                ]
            }
        };
    },
    computed: {
        ...EditCrud.computed
    },
    mounted() {
        this.init();
    },
    methods: {
        ...EditCrud.methods(API),
        assignModel(res) {
            this.model = Object.assign({}, res);
        },
        newModel() {
            this.model = Object.assign({}, {
                id: null,
                username: '',
                content: {
                    text: ''
                },
            });
        },
        onValidate(result) {
            this.validity = result.validity;
            this.valid = result.valid;
            console.log('validity', result.validity, result.valid, result.dirty, result.firstInvalidFieldIndex);
        },
        showDatePicker() {
            this.$refs.datePicker.show();
        },
        dateSelectHandler(selectedVal) {
            this.model.dateValue = new Date(selectedVal[0], selectedVal[1] - 1, selectedVal[2]).toDateString();
        }
    }
};
</script>
<style lang="scss" scoped>
    .page-opportunity-detail {

    }
</style>